package com.ruoyi.hospital.department.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.hospital.department.domain.TDepartment;
import com.ruoyi.hospital.department.service.ITDepartmentService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 科室管理Controller
 *
 * @author Shawn
 * @date 2024-02-20
 */
@Controller
@RequestMapping("/hospital/department")
public class TDepartmentController extends BaseController {
    private String prefix = "hospital/department";

    @Autowired
    private ITDepartmentService tDepartmentService;

    @RequiresPermissions("hospital:department:view")
    @GetMapping()
    public String department() {
        return prefix + "/department";
    }

    /**
     * 查询科室管理列表
     */
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TDepartment tDepartment) {
        startPage();
        List<TDepartment> list = tDepartmentService.selectTDepartmentList(tDepartment);
        return getDataTable(list);
    }

    /**
     * 导出科室管理列表
     */
    @RequiresPermissions("hospital:department:export")
    @Log(title = "科室管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TDepartment tDepartment) {
        List<TDepartment> list = tDepartmentService.selectTDepartmentList(tDepartment);
        ExcelUtil<TDepartment> util = new ExcelUtil<TDepartment>(TDepartment.class);
        return util.exportExcel(list, "科室管理数据");
    }

    /**
     * 新增科室管理
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存科室管理
     */
    @RequiresPermissions("hospital:department:add")
    @Log(title = "科室管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TDepartment tDepartment) {
        return toAjax(tDepartmentService.insertTDepartment(tDepartment));
    }

    /**
     * 修改科室管理
     */
    @RequiresPermissions("hospital:department:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap) {
        TDepartment tDepartment = tDepartmentService.selectTDepartmentById(id);
        mmap.put("tDepartment", tDepartment);
        return prefix + "/edit";
    }

    /**
     * 修改保存科室管理
     */
    @RequiresPermissions("hospital:department:edit")
    @Log(title = "科室管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TDepartment tDepartment) {
        return toAjax(tDepartmentService.updateTDepartment(tDepartment));
    }

    /**
     * 删除科室管理
     */
    @RequiresPermissions("hospital:department:remove")
    @Log(title = "科室管理", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(tDepartmentService.deleteTDepartmentByIds(ids));
    }


    @RequestMapping("/selectDepartment")
    public String selectDepartment() {
        return prefix+"/selectDepartment";
    }
}
